
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>3.1.4 web应用: koa框架 · Ebook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="zq_sdk@163.com">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-disqus/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tree/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-ace/ace.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-katex/katex.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="koa.html" />
    
    
    <link rel="prev" href="important.html" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"repo":"TIME-GATE/","types":["star","watch"],"size":"large"};
    </script>

    
    <link rel="stylesheet" href="../../gitbook/gitbook-plugin-chart/c3/c3.min.css">
    <script src="../../gitbook/gitbook-plugin-chart/c3/d3.min.js"></script>
    <script src="../../gitbook/gitbook-plugin-chart/c3/c3.min.js"></script>
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    简介
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" data-path="../../about_me.html">
            
                <a href="../../about_me.html">
            
                    
                    关于
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2" data-path="../../gitbook_install.html">
            
                <a href="../../gitbook_install.html">
            
                    
                    附:Gitbook安装
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../">
            
                <a href="../../">
            
                    
                    一 基础理论
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../../data_structure/">
            
                <a href="../../data_structure/">
            
                    
                    1 数据结构
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.1" data-path="../../data_structure/11_linear_structure.html">
            
                <a href="../../data_structure/11_linear_structure.html">
            
                    
                    1.1 数组、链表、跳表及字典
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.1.1" data-path="../../data_structure/111_array.html">
            
                <a href="../../data_structure/111_array.html">
            
                    
                    1.1.1 数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.1.2" data-path="../../data_structure/112_link_list.html">
            
                <a href="../../data_structure/112_link_list.html">
            
                    
                    1.1.2 链表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.1.3" data-path="../../data_structure/113_skip_list.html">
            
                <a href="../../data_structure/113_skip_list.html">
            
                    
                    1.1.3 跳表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.1.4" data-path="../../data_structure/114_dictionary.html">
            
                <a href="../../data_structure/114_dictionary.html">
            
                    
                    1.1.4 字典
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.1.2" data-path="../../data_structure/12_stack_and_queue.html">
            
                <a href="../../data_structure/12_stack_and_queue.html">
            
                    
                    1.2 栈、队列、散列及集合
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.2.1" data-path="../../data_structure/121_stack.html">
            
                <a href="../../data_structure/121_stack.html">
            
                    
                    1.2.1 栈
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2.2" data-path="../../data_structure/122_queue.html">
            
                <a href="../../data_structure/122_queue.html">
            
                    
                    1.2.2 队列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2.3" data-path="../../data_structure/123_hash.html">
            
                <a href="../../data_structure/123_hash.html">
            
                    
                    1.2.3 散列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2.4" data-path="../../data_structure/124_set.html">
            
                <a href="../../data_structure/124_set.html">
            
                    
                    1.2.4 集合
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.1.3" data-path="../../data_structure/13_tree_and_forest.html">
            
                <a href="../../data_structure/13_tree_and_forest.html">
            
                    
                    1.3 树与森林
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.3.1" data-path="../../data_structure/131.html">
            
                <a href="../../data_structure/131.html">
            
                    
                    1.3.1 二叉搜索树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.3.2" data-path="../../data_structure/132.html">
            
                <a href="../../data_structure/132.html">
            
                    
                    1.3.2 红黑树
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.1.4" data-path="../../data_structure/14_map.html">
            
                <a href="../../data_structure/14_map.html">
            
                    
                    1.4 图结构
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.4.1" data-path="../../data_structure/141_minimal_tree.html">
            
                <a href="../../data_structure/141_minimal_tree.html">
            
                    
                    1.4.1 最小生成树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.4.2" data-path="../../data_structure/142_single_source_shortest_path.html">
            
                <a href="../../data_structure/142_single_source_shortest_path.html">
            
                    
                    1.4.2 单源最短路径
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.4.3" data-path="../../data_structure/143_all_source_shortest_path.html">
            
                <a href="../../data_structure/143_all_source_shortest_path.html">
            
                    
                    1.4.3 多源最短路径
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.4.4" data-path="../../data_structure/144_max_stream.html">
            
                <a href="../../data_structure/144_max_stream.html">
            
                    
                    1.4.4 最大流
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../../">
            
                <a href="../../">
            
                    
                    2 基础算法
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="../../algorithm/21.html">
            
                <a href="../../algorithm/21.html">
            
                    
                    2.1 排序查找
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.2" data-path="../../algorithm/22.html">
            
                <a href="../../algorithm/22.html">
            
                    
                    2.2 动态规划
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../../algorithm/distributed_algorithm.html">
            
                <a href="../../algorithm/distributed_algorithm.html">
            
                    
                    3 分布式算法
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.3.1" data-path="../../engineering/ci_deplopment/cs/theory.html">
            
                <a href="../../engineering/ci_deplopment/cs/theory.html">
            
                    
                    3.1 一致性模式与理论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.2" data-path="../../algorithm/raft.html">
            
                <a href="../../algorithm/raft.html">
            
                    
                    3.2 Raft协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.3" data-path="../../algorithm/paxos.html">
            
                <a href="../../algorithm/paxos.html">
            
                    
                    3.3 Paxos协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.4" data-path="../../algorithm/gossip.html">
            
                <a href="../../algorithm/gossip.html">
            
                    
                    3.4 Gossip协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.5" data-path="../../engineering/ci_deplopment/cs/plan.html">
            
                <a href="../../engineering/ci_deplopment/cs/plan.html">
            
                    
                    3.5 几种一致性方案
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../../optimization_se/">
            
                <a href="../../optimization_se/">
            
                    
                    4 运筹及系统工程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.4.1" data-path="../../optimization_se/linear_programming.html">
            
                <a href="../../optimization_se/linear_programming.html">
            
                    
                    4.1 线性规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.2" data-path="../../optimization_se/integer_programming.html">
            
                <a href="../../optimization_se/integer_programming.html">
            
                    
                    4.2 整数规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.3" data-path="../../optimization_se/目标规划.html">
            
                <a href="../../optimization_se/目标规划.html">
            
                    
                    4.3 目标规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.4" data-path="../../optimization_se/非线性规划.html">
            
                <a href="../../optimization_se/非线性规划.html">
            
                    
                    4.4 非线性规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.5" data-path="../../optimization_se/动态规划.html">
            
                <a href="../../optimization_se/动态规划.html">
            
                    
                    4.5 动态规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.6" data-path="../../optimization_se/排队论.html">
            
                <a href="../../optimization_se/排队论.html">
            
                    
                    4.6 排队论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.7" data-path="../../optimization_se/博弈论.html">
            
                <a href="../../optimization_se/博弈论.html">
            
                    
                    4.7 博弈论
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    二 工程应用
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../engineering/design_pattern/">
            
                <a href="../../engineering/design_pattern/">
            
                    
                    1 设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1.1" data-path="../../engineering/design_pattern/strategy.html">
            
                <a href="../../engineering/design_pattern/strategy.html">
            
                    
                    1.1 策略模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.2" data-path="../../engineering/design_pattern/prototype.html">
            
                <a href="../../engineering/design_pattern/prototype.html">
            
                    
                    1.2 原型模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.3" data-path="../../engineering/design_pattern/singleton.html">
            
                <a href="../../engineering/design_pattern/singleton.html">
            
                    
                    1.3 单例模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.4" data-path="../../engineering/design_pattern/factory.html">
            
                <a href="../../engineering/design_pattern/factory.html">
            
                    
                    1.4 工厂模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.5" data-path="../../engineering/design_pattern/bridge.html">
            
                <a href="../../engineering/design_pattern/bridge.html">
            
                    
                    1.5 桥接模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.6" data-path="../../engineering/design_pattern/composite.html">
            
                <a href="../../engineering/design_pattern/composite.html">
            
                    
                    1.6 组合模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.7" data-path="../../engineering/design_pattern/facade.html">
            
                <a href="../../engineering/design_pattern/facade.html">
            
                    
                    1.7 门面模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.8" data-path="../../engineering/design_pattern/adapter.html">
            
                <a href="../../engineering/design_pattern/adapter.html">
            
                    
                    1.8 适配器模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.9" data-path="../../engineering/design_pattern/decorator.html">
            
                <a href="../../engineering/design_pattern/decorator.html">
            
                    
                    1.9 装饰者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.10" data-path="../../engineering/design_pattern/flyweight.html">
            
                <a href="../../engineering/design_pattern/flyweight.html">
            
                    
                    1.10 享元模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.11" data-path="../../engineering/design_pattern/proxy.html">
            
                <a href="../../engineering/design_pattern/proxy.html">
            
                    
                    1.11 代理模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.12" data-path="../../engineering/design_pattern/middleware.html">
            
                <a href="../../engineering/design_pattern/middleware.html">
            
                    
                    1.12 中间件模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../../engineering/network_prag/">
            
                <a href="../../engineering/network_prag/">
            
                    
                    2 网络编程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.2.1" data-path="../../engineering/network_prag/socket.html">
            
                <a href="../../engineering/network_prag/socket.html">
            
                    
                    2.1 长连接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2.2" data-path="../../engineering/network_prag/mq.html">
            
                <a href="../../engineering/network_prag/mq.html">
            
                    
                    2.2 MQ
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../">
            
                <a href="../">
            
                    
                    3 语言应用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.3.1" data-path="node.html">
            
                <a href="node.html">
            
                    
                    3.1 Node.js
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.3.1.1" data-path="core.html">
            
                <a href="core.html">
            
                    
                    3.1.1 原理及构成
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.2" data-path="async.html">
            
                <a href="async.html">
            
                    
                    3.1.2 异步机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.3" data-path="important.html">
            
                <a href="important.html">
            
                    
                    3.1.3 一些核心概念
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.3.1.4" data-path="koa_web.html">
            
                <a href="koa_web.html">
            
                    
                    3.1.4 web应用: koa框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.5" data-path="koa.html">
            
                <a href="koa.html">
            
                    
                    3.1.5 koa源码分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.6" data-path="libuv.html">
            
                <a href="libuv.html">
            
                    
                    3.1.6 libuv网络库应用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.7" data-path="apm.html">
            
                <a href="apm.html">
            
                    
                    3.1.7 性能调优
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.8" data-path="node_spider.html">
            
                <a href="node_spider.html">
            
                    
                    3.1.8 其他: Node爬虫
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.9" data-path="node_map_reduce.html">
            
                <a href="node_map_reduce.html">
            
                    
                    3.1.9 其他: Node编写Mapreduce
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.3.2" data-path="../c/c_and_plus.html">
            
                <a href="../c/c_and_plus.html">
            
                    
                    3.2 C/C++
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.3.2.1" data-path="../c/oop.html">
            
                <a href="../c/oop.html">
            
                    
                    3.2.1 面向对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.2.2" data-path="../c/ipcs.html">
            
                <a href="../c/ipcs.html">
            
                    
                    3.2.2 进程通信
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.2.3" data-path="../c/thread.html">
            
                <a href="../c/thread.html">
            
                    
                    3.2.3 线程管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.2.4" data-path="../c/memory.html">
            
                <a href="../c/memory.html">
            
                    
                    3.2.4 内存管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.2.5" data-path="../c/network.html">
            
                <a href="../c/network.html">
            
                    
                    3.2.5 网络编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.2.6" data-path="../c/build_tool.html">
            
                <a href="../c/build_tool.html">
            
                    
                    3.2.6 构建工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.2.7" data-path="../c/thread_pool.html">
            
                <a href="../c/thread_pool.html">
            
                    
                    3.2.7 其他: 线程池
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../../engineering/ci_deplopment/">
            
                <a href="../../engineering/ci_deplopment/">
            
                    
                    三 搭建部署
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../../engineering/ci_deplopment/test.html">
            
                <a href="../../engineering/ci_deplopment/test.html">
            
                    
                    3.1 测试
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1.1" data-path="../../engineering/ci_deplopment/test/unit_testing.html">
            
                <a href="../../engineering/ci_deplopment/test/unit_testing.html">
            
                    
                    3.1.1 单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.2" data-path="../../engineering/ci_deplopment/test/stress_testing.html">
            
                <a href="../../engineering/ci_deplopment/test/stress_testing.html">
            
                    
                    3.1.2 压力测试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../../engineering/ci_deplopment/ci_readme.html">
            
                <a href="../../engineering/ci_deplopment/ci_readme.html">
            
                    
                    3.2 集成
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.2.1" data-path="../../engineering/ci_deplopment/ci/gitlab_ci.html">
            
                <a href="../../engineering/ci_deplopment/ci/gitlab_ci.html">
            
                    
                    3.2.1 GitLab CI
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.2" data-path="../../engineering/ci_deplopment/ci/spinnaker.html">
            
                <a href="../../engineering/ci_deplopment/ci/spinnaker.html">
            
                    
                    3.2.2 Spinnaker
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../../engineering/ci_deplopment/build.html">
            
                <a href="../../engineering/ci_deplopment/build.html">
            
                    
                    3.3 部署
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.3.1" data-path="../../engineering/ci_deplopment/k8s/k8s.html">
            
                <a href="../../engineering/ci_deplopment/k8s/k8s.html">
            
                    
                    3.3.1 k8s
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3.2" data-path="../../engineering/ci_deplopment/rancher/rancher.html">
            
                <a href="../../engineering/ci_deplopment/rancher/rancher.html">
            
                    
                    3.3.2 rancher
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3.3" data-path="../../engineering/ci_deplopment/swarm/swarm.html">
            
                <a href="../../engineering/ci_deplopment/swarm/swarm.html">
            
                    
                    3.3.3 swarm
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../../engineering/ci_deplopment/maintenance.html">
            
                <a href="../../engineering/ci_deplopment/maintenance.html">
            
                    
                    3.4 监控
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.4.1" data-path="../../engineering/ci_deplopment/monitor.html">
            
                <a href="../../engineering/ci_deplopment/monitor.html">
            
                    
                    3.4.1 容器监控
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4.2" data-path="../../engineering/ci_deplopment/trace.html">
            
                <a href="../../engineering/ci_deplopment/trace.html">
            
                    
                    3.4.2 系统监控
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4.3" data-path="../../engineering/ci_deplopment/app1.md">
            
                <span>
            
                    
                    3.4.2 应用监控
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../../engineering/ha/ha.html">
            
                <a href="../../engineering/ha/ha.html">
            
                    
                    3.5 高可用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.5.1" data-path="../../engineering/ha/client.html">
            
                <a href="../../engineering/ha/client.html">
            
                    
                    3.5.1 接入层高可用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5.2" data-path="../../engineering/ha/service.html">
            
                <a href="../../engineering/ha/service.html">
            
                    
                    3.5.2 服务层高可用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5.3" data-path="../../engineering/ha/share.html">
            
                <a href="../../engineering/ha/share.html">
            
                    
                    3.5.3 存储层高可用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../../engineering/ci_deplopment/hc/hc.html">
            
                <a href="../../engineering/ci_deplopment/hc/hc.html">
            
                    
                    3.6 高并发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.6.1" data-path="../../engineering/ci_deplopment/hc/dns.html">
            
                <a href="../../engineering/ci_deplopment/hc/dns.html">
            
                    
                    3.6.1 基于DNS的负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6.2" data-path="../../engineering/ci_deplopment/hc/lvs.html">
            
                <a href="../../engineering/ci_deplopment/hc/lvs.html">
            
                    
                    3.6.2 基于Lvs的负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6.3" data-path="../../engineering/ci_deplopment/hc/haproxy.html">
            
                <a href="../../engineering/ci_deplopment/hc/haproxy.html">
            
                    
                    3.6.3 基于haproxy的负载均衡
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    四 架构模式
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" >
            
                <span>
            
                    
                    1 微服务架构设计与实践
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1.1" data-path="../java/spring-cloud.html">
            
                <a href="../java/spring-cloud.html">
            
                    
                    1.1 微服务概况
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.2" data-path="../java/spring-eureka.html">
            
                <a href="../java/spring-eureka.html">
            
                    
                    1.2 服务注册及发现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.3" data-path="../java/spring-feign.html">
            
                <a href="../java/spring-feign.html">
            
                    
                    1.3 服务调用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.4" data-path="../java/spring-zuul.html">
            
                <a href="../java/spring-zuul.html">
            
                    
                    1.4 网关及负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.5" data-path="../java/spring-hystrix.html">
            
                <a href="../java/spring-hystrix.html">
            
                    
                    1.5 熔断、限流、扩缩容
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.6" data-path="../java/spring-config.html">
            
                <a href="../java/spring-config.html">
            
                    
                    1.6 云配置中心
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.7" data-path="../java/zipkin-tracing.html">
            
                <a href="../java/zipkin-tracing.html">
            
                    
                    1.7 分布式链路追踪
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.8" data-path="../java/swagger.html">
            
                <a href="../java/swagger.html">
            
                    
                    1.8 接口文档管理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../../domain/">
            
                <a href="../../domain/">
            
                    
                    2 领域驱动模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.2.1" data-path="../../domain/domain.html">
            
                <a href="../../domain/domain.html">
            
                    
                    2.1 领域--Domain
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2.2" data-path="../../domain/entity.md">
            
                <span>
            
                    
                    2.2 领域实体--Entity
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2.3" data-path="../../domain/object.html">
            
                <a href="../../domain/object.html">
            
                    
                    2.3 值对象--Value Object
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2.4" data-path="../../domain/aggregate.html">
            
                <a href="../../domain/aggregate.html">
            
                    
                    2.4 聚合--Aggregate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2.5" data-path="../../domain/service.html">
            
                <a href="../../domain/service.html">
            
                    
                    2.5 服务--Services
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2.6" data-path="../../domain/event.html">
            
                <a href="../../domain/event.html">
            
                    
                    2.6 领域事件--Event
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2.7" data-path="../../domain/framework.html">
            
                <a href="../../domain/framework.html">
            
                    
                    2.7 几种常见的DDD架构
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5.3" >
            
                <span>
            
                    
                    3 架构技术的演化与趋势
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.3.1" >
            
                <span>
            
                    
                    3.1 架构技术的发展历史及现状
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3.2" >
            
                <span>
            
                    
                    3.2 Serverless无服务架构概念
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3.3" >
            
                <span>
            
                    
                    3.3 ServerMesh网格服务概念
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    五 其他
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../../story/talk.html">
            
                <a href="../../story/talk.html">
            
                    
                    5.1 小伙子,放松!
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >3.1.4 web应用: koa框架</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="&#x4E00;&#x3001;&#x7B80;&#x4ECB;">&#x4E00;&#x3001;&#x7B80;&#x4ECB;</h3>
<p>&#xA0;&#xA0;&#xA0;&#xA0;koa&#x662F;&#x7531;Express&#x539F;&#x73ED;&#x4EBA;&#x9A6C;&#x6253;&#x9020;&#x7684;&#xFF0C;&#x81F4;&#x529B;&#x4E8E;&#x6210;&#x4E3A;&#x4E00;&#x4E2A;&#x66F4;&#x5C0F;&#x3001;&#x66F4;&#x5BCC;&#x6709;&#x8868;&#x73B0;&#x529B;&#x3001;&#x66F4;&#x5065;&#x58EE;&#x7684;Web&#x6846;&#x67B6;&#xFF0C;Koa&#x4E0D;&#x5B9A;&#x5236;&#x8DEF;&#x7531;&#xFF0C;&#x65E0;&#x5197;&#x4F59;&#x7684;&#x4E2D;&#x95F4;&#x4EF6;&#xFF0C;&#x5F00;&#x53D1;&#x8BBE;&#x8BA1;&#x65B9;&#x6848;&#x8D8B;&#x5411;&#x5B9A;&#x5236;&#x5316;&#xFF0C;&#x6240;&#x4EE5;&#x5F88;&#x9002;&#x5408;&#x5BF9;&#x4E1A;&#x52A1;&#x548C;&#x6280;&#x672F;&#x6709;&#x7075;&#x6D3B;&#x8981;&#x6C42;&#x7684;web&#x573A;&#x666F;&#x3002;</p>
<hr>
<h3 id="&#x4E8C;&#x3001;&#x5E94;&#x7528;">&#x4E8C;&#x3001;&#x5E94;&#x7528;</h3>
<p>&#xA0;&#xA0;&#xA0;&#xA0;&#x672C;&#x5C0F;&#x8282;&#x4FA7;&#x91CD;&#x4E8E;&#x5206;&#x4EAB;&#x4EE5;&#x4E0B;&#x51E0;&#x70B9;:</p>
<pre><code>1&#x3001;&#x8DEF;&#x7531;&#x8F6C;&#x53D1;&#x65F6;&#xFF0C;&#x5982;&#x4F55;&#x5229;&#x7528;&#x94A9;&#x5B50;&#x51FD;&#x6570;&#x673A;&#x5236;&#x505A;&#x5230;controller&#x5C42;&#x4E1A;&#x52A1;&#x89E3;&#x8026;
2&#x3001;&#x5728;socket&#x901A;&#x4FE1;&#x4E2D;&#x5982;&#x4F55;&#x52A8;&#x6001;&#x52A0;&#x8F7D;protobuf&#x8FDB;&#x884C;&#x6570;&#x636E;&#x683C;&#x5F0F;&#x4EA4;&#x6362;
3&#x3001;&#x5982;&#x4F55;&#x57FA;&#x4E8E;websocket&#x7ED1;&#x5B9A;&#x76F8;&#x540C;&#x7684;&#x7AEF;&#x53E3;
4&#x3001;&#x5982;&#x4F55;&#x5229;&#x7528;c++&#x7F16;&#x5199;node&#x6269;&#x5C55;&#x5E93;
</code></pre><hr>
<ul>
<li>2.1 &#x4E1A;&#x52A1;&#x89E3;&#x8026;</li>
</ul>
<p>&#xA0;&#xA0;&#xA0;&#xA0;&#x4E2D;&#x95F4;&#x4EF6;&#x53CA;&#x94A9;&#x5B50;&#x51FD;&#x6570;&#x673A;&#x5236;&#x7686;&#x4E3A;&#x4E1A;&#x52A1;&#x89E3;&#x8026;&#x7684;&#x6709;&#x6548;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#xFF0C;&#x5176;&#x4E2D;&#x4E2D;&#x95F4;&#x4EF6;&#x6A21;&#x5F0F;&#x56E0;&#x5176;&#x5B9E;&#x73B0;&#x65B9;&#x4FBF;&#x800C;&#x5E94;&#x7528;&#x5E7F;&#x6CDB;, &#x5982;koa&#x3001;express&#x3001;sails&#x4E2D;&#x90FD;&#x66FE;&#x5927;&#x91CF;&#x7528;&#x5230;&#xFF0C;&#x800C;&#x94A9;&#x5B50;&#x51FD;&#x6570;&#x673A;&#x5236;&#x5728;node&#x751F;&#x6001;&#x4E2D;&#x5219;&#x88AB;&#x5927;&#x91CF;&#x7528;&#x5230;ORM&#x5BF9;&#x6570;&#x636E;&#x5E93;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x5982;mongoose&#x3001;waterline&#xFF0C;&#x5728;&#x63A7;&#x5236;&#x5C42;&#x7684;&#x5E94;&#x7528;&#x8F83;&#x5C11;&#xFF0C;&#x5982;&#x4E0B;&#x5C1D;&#x8BD5;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x7B80;&#x6613;&#x7684;&#x63A5;&#x53E3;&#x5C42;Hook&#xFF0C;&#x5E76;&#x5E94;&#x7528;&#x5728;koa&#x6846;&#x67B6;&#x4E2D;&#x3002;</p>
<p>&#x7F16;&#x5199;koa-hooks, &#x5E76;&#x63D0;&#x4EA4;&#x5230;npm, <a href="https://www.npmjs.com/package/koa-hooks" target="_blank">https://www.npmjs.com/package/koa-hooks</a></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> hooks = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;hooks&apos;</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ApiHooks</span> </span>{

  <span class="hljs-keyword">constructor</span>(ctx, next, cb) {
    <span class="hljs-keyword">this</span>._ctx = ctx
    <span class="hljs-keyword">this</span>._next = next
    <span class="hljs-keyword">this</span>._cb = cb
    <span class="hljs-keyword">this</span>._listenerTree = {}
    <span class="hljs-keyword">this</span>.addListenerTree()     
  }

  addListenerTree() {
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> fn <span class="hljs-keyword">in</span> hooks) {
      <span class="hljs-keyword">this</span>[fn] = hooks[fn]
    }
  }

  addHooks(listeners) {
    <span class="hljs-keyword">const</span> self = <span class="hljs-keyword">this</span>

    <span class="hljs-keyword">try</span> {
      listeners.map(listener =&gt; {
        <span class="hljs-keyword">const</span> [method, hooksFn] = listener.split(<span class="hljs-string">&apos;.&apos;</span>)
        <span class="hljs-keyword">if</span>(hooksFn.match(<span class="hljs-string">&apos;before&apos;</span>)) self.addFn(method, hooksFn, <span class="hljs-string">&apos;pre&apos;</span>)
        <span class="hljs-keyword">if</span>(hooksFn.match(<span class="hljs-string">&apos;after&apos;</span>)) self.addFn(method, hooksFn, <span class="hljs-string">&apos;post&apos;</span>)
      })
    } <span class="hljs-keyword">catch</span> (err) {
      <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;err:&apos;</span>, err)  
    }

  }

 addFn(method, hooksFn, hook) {
    <span class="hljs-keyword">const</span> self = <span class="hljs-keyword">this</span>
    self[hook](method, <span class="hljs-keyword">async</span> (next) =&gt; {
      <span class="hljs-keyword">await</span> self[hooksFn](self._ctx, next, self._cb)
    })
  }

}

<span class="hljs-built_in">module</span>.exports = ApiHooks
</code></pre>
<p>&#x7F16;&#x5199;&#x4E00;&#x4E2A;restful&#x98CE;&#x683C;&#x63A5;&#x53E3;<code>/v1/verb/get</code>&#xFF0C;&#x7EE7;&#x627F;ApiHooks, &#x6DFB;&#x52A0;&#x5BF9;&#x5E94;&#x7684;&#x94A9;&#x5B50;&#x51FD;&#x6570;beforeVerbCheckLogin&#x5B9E;&#x73B0;&#x767B;&#x5F55;&#x68C0;&#x67E5;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">/**
 * Created by Joseph on 18/09/2017. 
 */</span>

<span class="hljs-keyword">const</span> Api = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;koa-hooks&apos;</span>).Api
<span class="hljs-keyword">const</span> VerbService = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;../../services/verb.js&apos;</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">VerbApi</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Api</span> </span>{
  <span class="hljs-keyword">constructor</span>(ctx, next, cb) {
    <span class="hljs-keyword">super</span>(ctx, next, cb)
    <span class="hljs-keyword">this</span>.addHooks([
      <span class="hljs-string">&apos;verbGetOnThisRequest.beforeVerbCheckLogin&apos;</span>,
      <span class="hljs-string">&apos;verbPostOnThisRequest.beforeVerbCheckLogin&apos;</span>,
      <span class="hljs-string">&apos;verbPutOnThisRequest.beforeVerbCheckLogin&apos;</span>,
      <span class="hljs-string">&apos;verbDeleteOnThisRequest.beforeVerbCheckLogin&apos;</span>,
    ])
  }

  <span class="hljs-keyword">async</span> beforeVerbCheckLogin(ctx, next, cb) {
    <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> VerbService.beforeVerbCheckLogin(ctx, next)
    data ? cb(ctx, data) : <span class="hljs-keyword">await</span> next()
  }

  <span class="hljs-keyword">async</span> verbGetOnThisRequest(ctx, next, cb) {
    <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> VerbService.verbGetOnThisTest(ctx, next)
    data ? cb(ctx, data) : <span class="hljs-keyword">await</span> next()
  }

  <span class="hljs-keyword">async</span> verbPostOnThisRequest(ctx, next, cb) {
    <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> VerbService.verbPostOnThisTest(ctx, next)
    data ? cb(ctx, data) : <span class="hljs-keyword">await</span> next()
  }

  <span class="hljs-keyword">async</span> verbPutOnThisRequest(ctx, next, cb) {
    <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> VerbService.verbPutOnThisTest(ctx, next)
    data ? cb(ctx, data) : <span class="hljs-keyword">await</span> next()
  }

  <span class="hljs-keyword">async</span> verbDeleteOnThisRequest(ctx, next, cb) {
    <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> VerbService.verbDeleteOnThisTest(ctx, next)
    data ? cb(ctx, data) : <span class="hljs-keyword">await</span> next()
  }

}

<span class="hljs-built_in">module</span>.exports = (ctx, next, cb) =&gt; <span class="hljs-keyword">new</span> VerbApi(ctx, next, cb)
</code></pre>
<p>&#x542F;&#x52A8;&#x670D;&#x52A1;&#xFF0C;&#x8BF7;&#x6C42;&#x63A5;&#x53E3;<a href="http://127.0.0.1:3000/v1/verb/get&#xFF0C;&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#x6B64;&#x94A9;&#x5B50;&#x51FD;&#x6570;&#x5DF2;&#x7ECF;&#x751F;&#x6548;" target="_blank">http://127.0.0.1:3000/v1/verb/get&#xFF0C;&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#x6B64;&#x94A9;&#x5B50;&#x51FD;&#x6570;&#x5DF2;&#x7ECF;&#x751F;&#x6548;</a></p>
<p><img src="http://oy1w4m5vz.bkt.clouddn.com/koa_1.png" alt=""></p>
<p>&#x6CE8;&#x91CA;&#x6389;//&apos;verbGetOnThisRequest.beforeVerbCheckLogin&apos;, &#x518D;&#x6B21;&#x8BF7;&#x6C42;&#x63A5;&#x53E3;&#xFF0C;&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#x5728;&#x9700;&#x6C42;&#x53D8;&#x52A8;&#x60C5;&#x51B5;&#x5BF9;&#x6E90;&#x7801;&#x4FEE;&#x6539;&#x6781;&#x5C11;&#xFF0C;&#x4EE3;&#x7801;&#x53EF;&#x7EF4;&#x62A4;&#x6027;&#x63D0;&#x5347;</p>
<p><img src="http://oy1w4m5vz.bkt.clouddn.com/koa_2.png" alt=""></p>
<hr>
<ul>
<li>2.2 protobuf&#x6570;&#x636E;&#x534F;&#x8BAE;</li>
</ul>
<p>&#xA0;&#xA0;&#xA0;&#xA0;protobuf&#x662F;&#x8C37;&#x6B4C;&#x5F00;&#x6E90;&#x7684;&#x662F;&#x4E00;&#x79CD;&#x8F7B;&#x4FBF;&#x9AD8;&#x6548;&#x7684;&#x7ED3;&#x6784;&#x5316;&#x6570;&#x636E;&#x5B58;&#x50A8;&#x683C;&#x5F0F;, &#x4E14;&#x5E73;&#x53F0;&#x65E0;&#x5173;&#x3001;&#x8BED;&#x8A00;&#x65E0;&#x5173;&#x3001;&#x53EF;&#x6269;&#x5C55;&#xFF0C;&#x901A;&#x5E38;&#x7528;&#x5728;tcp&#x7F16;&#x7A0B;&#x5BF9;&#x6570;&#x636E;&#x4F20;&#x8F93;&#x8981;&#x6C42;&#x8F83;&#x9AD8;&#x7684;&#x573A;&#x666F;&#xFF0C;protobuf&#x517C;&#x6709;json&#x7684;&#x53EF;&#x8BFB;&#x6027;&#xFF0C;&#x4E14;&#x4F20;&#x8F93;&#x6548;&#x7387;&#x8FDC;&#x5927;&#x4E8E;json&#x3001;xml&#x7B49;&#xFF0C;&#x975E;&#x5E38;&#x9002;&#x5408;&#x6D41;&#x5F0F;&#x6570;&#x636E;&#x4EA4;&#x6362;&#x3002;</p>
<p>A) &#x6839;&#x636E;&#x6587;&#x4EF6;&#x540D;&#x53CA;message&#x52A8;&#x6001;&#x52A0;&#x8F7D;protobuf</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> protobuf = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;protobufjs&apos;</span>)
<span class="hljs-keyword">const</span> protoPath = <span class="hljs-string">&apos;/Users/dreamboad/Projects/koa-service/message/&apos;</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Proto</span> </span>{

  <span class="hljs-keyword">async</span> loadByName(protoName, messageName, obj, type) {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>((resolve, reject) =&gt; {
      protobuf.load(<span class="hljs-string">`<span class="hljs-subst">${protoPath}</span><span class="hljs-subst">${protoName}</span>.proto`</span>, (err, root) =&gt; {

        <span class="hljs-keyword">if</span> (err) {
          <span class="hljs-keyword">return</span> <span class="hljs-built_in">console</span>.log(err) || resolve()
        }

        <span class="hljs-keyword">const</span> data = root.lookupType(<span class="hljs-string">`<span class="hljs-subst">${protoName}</span>.<span class="hljs-subst">${messageName}</span>`</span>)

        <span class="hljs-keyword">if</span> (type === <span class="hljs-string">&apos;encode&apos;</span> &amp;&amp; data.verify(obj)) {
          <span class="hljs-keyword">return</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;encode err&apos;</span>) || resolve()
        }

        <span class="hljs-keyword">switch</span> (type) {
          <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;decode&apos;</span>:
            <span class="hljs-keyword">return</span> resolve(data.toObject(data.decode(obj), { objects: <span class="hljs-literal">true</span> }))
          <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;encode&apos;</span>:
            <span class="hljs-keyword">return</span> resolve(data.encode(data.create(obj) || <span class="hljs-string">&apos;&apos;</span>).finish())
        }
      })
    })
  }

  <span class="hljs-keyword">async</span> deserialize(protoName, messageName, obj) {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.loadByName(protoName, messageName, obj, <span class="hljs-string">&apos;decode&apos;</span>)
  }

  <span class="hljs-keyword">async</span> serialize(protoName, messageName, obj) {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.loadByName(protoName, messageName, obj, <span class="hljs-string">&apos;encode&apos;</span>)
  }

}

<span class="hljs-built_in">module</span>.exports = <span class="hljs-keyword">new</span> Proto()
</code></pre>
<p>B) &#x7F16;&#x5199;soket client</p>
<pre><code class="lang-javascript"><span class="hljs-comment">/**
 * 1&#x3001;&#x52A8;&#x6001;&#x52A0;&#x8F7D;protobuf
 * 2&#x3001;socket&#x6570;&#x636E;&#x6D41;&#x65AD;&#x5305;&#x3001;&#x7C98;&#x5305;&#x5904;&#x7406;(TODO)
 * 3&#x3001;&#x5FC3;&#x8DF3;&#x673A;&#x5236;&#x3001;&#x53CA;&#x65AD;&#x7EBF;&#x91CD;&#x8FDE;
 */</span>

<span class="hljs-keyword">const</span> net = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;net&apos;</span>)

<span class="hljs-keyword">const</span> [HOST, PORT] = [<span class="hljs-string">&apos;127.0.0.1&apos;</span>, <span class="hljs-number">9999</span>]

<span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> net.Socket()

<span class="hljs-keyword">const</span> connection = () =&gt; {
  client.connect(PORT, HOST, () =&gt; { <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;CONNECTED TO: &apos;</span> + HOST + <span class="hljs-string">&apos;:&apos;</span> + PORT)})
}

client.on(<span class="hljs-string">&apos;data&apos;</span>, (data) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${HOST}</span>:<span class="hljs-subst">${PORT}</span> CONNECT DATA: `</span>, data)
})

client.on(<span class="hljs-string">&apos;error&apos;</span>, (e) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${HOST}</span>:<span class="hljs-subst">${PORT}</span> CONNECT ERROR: `</span> + e)
})

client.on(<span class="hljs-string">&apos;timeout&apos;</span>, (e) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${HOST}</span>:<span class="hljs-subst">${PORT}</span> CONNECT TIMEOUT: `</span> + e)
})

client.on(<span class="hljs-string">&apos;end&apos;</span>, (e) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${HOST}</span>:<span class="hljs-subst">${PORT}</span> CONNECT END: `</span> + e)
})

client.on(<span class="hljs-string">&apos;close&apos;</span>, (e) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${HOST}</span>:<span class="hljs-subst">${PORT}</span> CONNECT CLOSE: `</span> + e)

  <span class="hljs-keyword">if</span> (client.destroyed) {
    client.destroy()
  }

  setTimeout(connection, <span class="hljs-number">3000</span>)
})

process.on(<span class="hljs-string">&apos;exit&apos;</span>, () =&gt; {
  client.destroy()

  client.on(<span class="hljs-string">&apos;close&apos;</span>, () =&gt; {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;Connection closed&apos;</span>)
  })

})

<span class="hljs-comment">// &#x8FDE;&#x63A5; &#x5BA2;&#x6237;&#x7AEF;</span>
<span class="hljs-built_in">module</span>.exports = { connection, client }
</code></pre>
<p>C) &#x5728;soket&#x901A;&#x4FE1;&#x4E2D;&#x5E8F;&#x5217;&#x5316;/&#x53CD;&#x5E8F;&#x5217;&#x5316;json&#x6570;&#x636E;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">/**
 *  &#x5E8F;&#x5217;&#x5316;&#x3001;&#x53CD;&#x5E8F;&#x5217;&#x5316;
 */</span>
<span class="hljs-keyword">const</span> crypto = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;crypto&apos;</span>)
<span class="hljs-keyword">const</span> Proto = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./protobuf&apos;</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SocketProto</span> </span>{

  <span class="hljs-keyword">async</span> doTranslation(obj, protoName, messageName, operation) {

    <span class="hljs-keyword">try</span> {
      <span class="hljs-keyword">switch</span> (operation) {
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;decode&apos;</span>:
          <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> Proto.deserialize(obj, protoName, messageName)
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;encode&apos;</span>:
          <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> Proto.serialize(obj, protoName, messageName)
      }
    } <span class="hljs-keyword">catch</span> (error) {
      <span class="hljs-built_in">console</span>.log(error)
    }

  }

  <span class="hljs-keyword">async</span> decode(obj, protoName, messageName) {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.doTranslation(obj, protoName, messageName, <span class="hljs-string">&apos;decode&apos;</span>)
  }

  <span class="hljs-keyword">async</span> encode(obj, protoName, messageName) {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.doTranslation(obj, protoName, messageName, <span class="hljs-string">&apos;encode&apos;</span>)
  }

}

<span class="hljs-built_in">module</span>.exports = <span class="hljs-keyword">new</span> SocketProto()
</code></pre>
<p>D) &#x8FDE;&#x63A5;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x8BFB;&#x5199;&#x6D41;&#x5F0F;&#x6570;&#x636E;&#xFF0C;&#x5E76;&#x7528;proto&#x89E3;&#x6790;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> { connection, client } = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./socket_client&apos;</span>)
<span class="hljs-keyword">const</span> SocketProto = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./socket_protobuf&apos;</span>)
<span class="hljs-keyword">const</span> config = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;../config/&apos;</span>).msgIdConfig

connection()

<span class="hljs-keyword">const</span> writer = <span class="hljs-built_in">module</span>.exports.writer = <span class="hljs-keyword">async</span> (protoName, messageName, obj) =&gt; {
  <span class="hljs-keyword">const</span> w = <span class="hljs-keyword">await</span> SocketProto.encode(protoName, messageName, obj)
  <span class="hljs-keyword">return</span> client.write(w)
}

<span class="hljs-keyword">const</span> reader = <span class="hljs-built_in">module</span>.exports.reader = <span class="hljs-keyword">async</span> (protoName, messageName, obj) =&gt; {
  <span class="hljs-keyword">const</span> r = <span class="hljs-keyword">await</span> SocketProto.decode(protoName, messageName, obj)
  <span class="hljs-keyword">return</span> r
}

client.on(<span class="hljs-string">&apos;data&apos;</span>, (buf) =&gt; {
  chooseFnByMsg(<span class="hljs-string">&apos;&apos;</span>, <span class="hljs-string">&apos;basemsg&apos;</span>, buf)
})

<span class="hljs-keyword">const</span> chooseFnByMsg = (msgId, type, obj) =&gt; {

  <span class="hljs-keyword">if</span> (msgId) {
    <span class="hljs-keyword">if</span> (!config[msgId] || !config[msgId].req || !config[msgId].res) {
      <span class="hljs-keyword">return</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;noting to do: &apos;</span>, msgId)
    }
  }

  <span class="hljs-keyword">switch</span> (type) {
    <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;basemsg&apos;</span>:
      <span class="hljs-keyword">return</span> reader(config.head.res.pName, config.head.res.mName, obj)
    <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;write&apos;</span>:
      <span class="hljs-keyword">return</span> writer(config[msgId].req.pName, config[msgId].req.mName, obj)
    <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;read&apos;</span>:
      <span class="hljs-keyword">return</span> reader(config[msgId].res.pName, config[msgId].res.mName, obj)
    <span class="hljs-keyword">default</span>:
      <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;noting to do default: &apos;</span>, msgId)
      <span class="hljs-keyword">break</span>
  }

}

chooseFnByMsg(<span class="hljs-number">1</span>, <span class="hljs-string">&apos;write&apos;</span>, { Field: <span class="hljs-string">&quot;String&quot;</span> })

<span class="hljs-built_in">module</span>.exports = chooseFnByMsg
</code></pre>
<p>E) server&#x53CA;client&#x5206;&#x522B;&#x5728;&#x7EC8;&#x7AEF;&#x6253;&#x5370;&#x7ED3;&#x679C;</p>
<p><img src="http://oy1w4m5vz.bkt.clouddn.com/proto_server.png" alt=""></p>
<p><img src="http://oy1w4m5vz.bkt.clouddn.com/proto_client.png" alt=""></p>
<ul>
<li>2.3 websocket</li>
</ul>
<p>A) koa server</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> app = <span class="hljs-keyword">new</span> Koa()

<span class="hljs-comment">// web socket</span>
<span class="hljs-keyword">const</span> server = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;http&apos;</span>).Server(app.callback())
<span class="hljs-keyword">const</span> io = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io&apos;</span>)(server)

io.on(<span class="hljs-string">&apos;connection&apos;</span>, client =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;new connection:&apos;</span>)

  client.on(<span class="hljs-string">&apos;news&apos;</span>, (data, cb) =&gt; {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;news:&apos;</span>, data)
  })

  client.on(<span class="hljs-string">&apos;disconnect&apos;</span>, () =&gt; {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;disconnect:&apos;</span>)
  })

})
</code></pre>
<p>B) websocket client</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> client = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;socket.io-client&apos;</span>).connect(<span class="hljs-string">&apos;http://localhost:3000&apos;</span>)

client.emit(<span class="hljs-string">&apos;news&apos;</span>, <span class="hljs-string">&quot;hello world&quot;</span>)
</code></pre>
<p><img src="http://oy1w4m5vz.bkt.clouddn.com/koa_3.png" alt="koa_3"></p>
<ul>
<li>2.1 C++&#x63D2;&#x4EF6;</li>
</ul>
<p>&#xA0;&#xA0;&#xA0;&#xA0;IO&#x5F02;&#x6B65;&#x53CA;&#x9AD8;&#x5E76;&#x53D1;&#x662F;Node&#x7684;&#x4F18;&#x52BF;&#xFF0C;&#x4F46;&#x82E5;&#x5728;&#x9700;&#x8981;&#x5BC6;&#x96C6;&#x8BA1;&#x7B97;&#x3001;&#x96C6;&#x6210;&#x57FA;&#x4E8E;C++&#x7684;&#x7B2C;&#x4E09;&#x65B9;SDK&#x7B49;&#x573A;&#x666F;&#x65F6;&#xFF0C;Node&#x7684;&#x52A3;&#x52BF;&#x5219;&#x663E;&#x73B0;&#x51FA;&#x6765;&#xFF0C;&#x6B64;&#x65F6;&#x53EF;&#x4EE5;&#x57FA;&#x4E8E;node-gyp&#x6765;&#x5D4C;&#x5165;&#x96C6;&#x6210;C++&#x89E3;&#x51B3;&#x4EE5;&#x4E0A;&#x7B49;&#x95EE;&#x9898;&#x3002;</p>
<p>A) &#x5B89;&#x88C5;node-gyp</p>
<pre><code class="lang-javascript">cnpm install -g node-gyp
</code></pre>
<p>A) &#x7F16;&#x8F91;binding.gyp&#x3001;C++&#x3001;Node&#x8C03;&#x7528;&#x6A21;&#x5757;</p>
<pre><code class="lang-json">{
  <span class="hljs-string">&quot;targets&quot;</span>: [

    { 
            <span class="hljs-string">&quot;target_name&quot;</span>: <span class="hljs-string">&quot;demo&quot;</span>, 
            <span class="hljs-string">&quot;sources&quot;</span>: [<span class="hljs-string">&quot;src/demo.cc&quot;</span>] 
        },

       { 
            <span class="hljs-string">&quot;target_name&quot;</span>: <span class="hljs-string">&quot;test_params_nocb&quot;</span>, 
            <span class="hljs-string">&quot;sources&quot;</span>: [<span class="hljs-string">&quot;src/test_params_nocb.cc&quot;</span>] 
        },

      { 
            <span class="hljs-string">&quot;target_name&quot;</span>: <span class="hljs-string">&quot;test_function_nocb&quot;</span>, 
            <span class="hljs-string">&quot;sources&quot;</span>: [<span class="hljs-string">&quot;src/test_function_nocb.cc&quot;</span>] 
        },

    {
      <span class="hljs-string">&quot;target_name&quot;</span>: <span class="hljs-string">&quot;test_params_function_nocb&quot;</span>,
      <span class="hljs-string">&quot;sources&quot;</span>: [<span class="hljs-string">&quot;src/test_params_function_nocb.cc&quot;</span>]
    }
    ]
}
</code></pre>
<pre><code class="lang-javascript">// test_function_nocb.cc
#include &lt;node.h&gt;

namespace demo {

using v8::Function;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Null;
using v8::Object;
using v8::String;
using v8::Value;

void RunCallback(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {
  Isolate* isolate = args.GetIsolate();
  Local&lt;Function&gt; cb = Local&lt;Function&gt;::Cast(args[0]);
  Local&lt;Value&gt; argv[1] = { String::NewFromUtf8(isolate, &quot;hello world&quot;) };
  cb-&gt;Call(Null(isolate), 1, argv);
}

void Init(Local&lt;Object&gt; exports, Local&lt;Object&gt; module) {
  NODE_SET_METHOD(module, &quot;exports&quot;, RunCallback);
}

NODE_MODULE(test_function_nocb, Init)

}  // namespace demo
</code></pre>
<pre><code class="lang-javascript"><span class="hljs-built_in">module</span>.exports.embeddedProxy = (cb, params) =&gt; {
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>((resolve, reject) =&gt; {
    <span class="hljs-keyword">try</span> {
      <span class="hljs-keyword">return</span> cb((data) =&gt; { resolve(data) }, params)
    } <span class="hljs-keyword">catch</span> (err) {
      <span class="hljs-keyword">return</span> resolve({ data: <span class="hljs-string">&quot;&#x8C03;&#x7528;&#x5931;&#x8D25;&quot;</span>, code: <span class="hljs-number">-1</span> })
    }
  })
}
</code></pre>
<p>C) &#x7F16;&#x8BD1;C++</p>
<pre><code>node-gyp configure
node-gyp build
</code></pre><p><img src="http://oy1w4m5vz.bkt.clouddn.com/koa_4.png" alt="koa_4">
<img src="http://oy1w4m5vz.bkt.clouddn.com/koa_5.png" alt="koa_5"></p>
<p>D) &#x5B9A;&#x4E49;&#x8DEF;&#x7531;&#x5E76;&#x8C03;&#x7528;&#x63A5;&#x53E3;</p>
<p><img src="http://oy1w4m5vz.bkt.clouddn.com/koa_6.png" alt="koa_6"></p>
<hr>
<h3 id="&#x4E09;&#x3001;&#x53C2;&#x8003;">&#x4E09;&#x3001;&#x53C2;&#x8003;</h3>
<ul>
<li><a href="https://koa.bootcss.com/" target="_blank">1&#x3001;koa&#x6587;&#x6863;</a></li>
<li><a href="https://www.npmjs.com/package/protobufjs" target="_blank">2&#x3001;protobufjs&#x3001;npm</a></li>
<li><a href="https://www.npmjs.com/package/koa-hooks" target="_blank">3&#x3001;koa-hooks&#x3001;npm</a></li>
<li><a href="https://github.com/TIME-GATE/koa-service" target="_blank">4&#x3001;Github&#x6E90;&#x7801;</a></li>
<li><a href="https://www.npmjs.com/package/node-gyp" target="_blank">5&#x3001;Node-gyp</a></li>
</ul>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; &#x4E00;&#x84D1;&#x70DF;&#x96E8;&#x4EFB;&#x5E73;&#x751F; all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x4FEE;&#x6539;&#x65F6;&#x95F4;: 
2021-04-09 11:09:02
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="important.html" class="navigation navigation-prev " aria-label="Previous page: 3.1.3 一些核心概念">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="koa.html" class="navigation navigation-next " aria-label="Next page: 3.1.5 koa源码分析">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"3.1.4 web应用: koa框架","level":"1.3.3.1.4","depth":4,"next":{"title":"3.1.5 koa源码分析","level":"1.3.3.1.5","depth":4,"path":"program/nodejs/koa.md","ref":"program/nodejs/koa.md","articles":[]},"previous":{"title":"3.1.3 一些核心概念","level":"1.3.3.1.3","depth":4,"path":"program/nodejs/important.md","ref":"program/nodejs/important.md","articles":[]},"dir":"ltr"},"config":{"plugins":["disqus","tree","splitter","local-video","chart","github-buttons","tbfed-pagefooter","ace","katex"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy 一蓑烟雨任平生","modify_label":"修改时间: ","modify_format":"YYYY-MM-DD HH:mm:ss"},"disqus":{"useIdentifier":false,"shortName":"gitbookuse"},"ace":{},"splitter":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"katex":{},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"github-buttons":{"repo":"TIME-GATE/","types":["star","watch"],"size":"large"},"local-video":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"tree":{},"chart":{"type":"c3"}},"theme":"default","author":"zq_sdk@163.com","name":"name","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Ebook","language":"zh-hans","gitbook":"*","description":"电子书"},"file":{"path":"program/nodejs/koa_web.md","mtime":"2021-04-09T03:09:02.248Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-04-10T12:23:44.633Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.16.1/URI.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-disqus/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-tree/jquery.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-tree/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-ace/ace/ace.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-ace/ace.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

